Cleaned up DRY code