Refactoring to include phantomjs and casperjs