Various changes to improve testability using CasperJS.