Tests refactored. Fixed some errors.