Added some functions and code improvements.