started to refactor the code I found on internet