Removing repeating code