Fix minor bug and some code cleanup. #220
Fix casperjs tests. #220