refactor of found bug - prepared tests and debugged