Adding some functions and cleaning code.