Modified to work with phantomjs