Removed some duplicated code that there was a function for