refactored to comply with design