Clean up some code and add random functions