Update and Refactor code