refactoring code. DONT WORK