Added lots of not so DRY functions to improve performance