Added support for multiple views, did minor refactoring