simplified code and improved tests output