Removed some code duplication