lots of refactoring, added isstatement