tests and fixing code based on tests