Removing repeated code