Optomized a bunch of code

Added a new currenttime function to stop repetition and moved some declarations.