Written tests and changed the code so to work properly