fixed errors, code refactoring, added simple logger