Removed some code repetition