Update to refactor code a bit to make it cleaner.