fixed conditions
added tests