Done refactor. Changed most of the code.