cleaned up code duplication