Added some functions, cleaned code.