refactored into multiple files & added phantomjs test suite