Added some helper functions, and removed some redundancies