fairly big refactor and phantomjs