Simplified similar code

Reworked the similar code as it is basically identical throughout.