Reimplemented functions and code cleanup