Cleaning up code duplication