Add tests for conditions, fix bugs