added support for iterating objects, also did a lot of refactoring