getClasses (s:ss) t = do env <- liftIO $ readIORef s
                         rest <- getClasses ss t
                         return (findClasses env t [] ++ rest)
                 where
                    findClasses [] _ acc = acc
                    findClasses ((Class f, v):es) t acc | match t f = findClasses es t ((Class f, v) : acc)
                                                        | otherwise = findClasses es t acc
                    findClasses (_:es) t acc = findClasses es t acc
getClasses (s:ss) t = do env <- liftIO $ readIORef s
                         rest <- getClasses ss t
                         return (findClasses env t [] ++ rest)
                 where
                    findClasses [] _ acc = acc
                    findClasses ((Class f, v):es) t acc | match t f = findClasses es t ((Class f, v) : acc)
                                                        | otherwise = findClasses es t acc
                    findClasses (_:es) t acc = findClasses es t acc
getClasses (s:ss) t = do env <- liftIO $ readIORef s
                         rest <- getClasses ss t
                         return (findClasses env t [] ++ rest)
                 where
                    findClasses [] _ acc = acc
                    findClasses ((Class f, v):es) t acc | match t f = findClasses es t ((Class f, v) : acc)
                                                        | otherwise = findClasses es t acc
                    findClasses (_:es) t acc = findClasses es t acc