Started to refactor code