removed some code repetition