removing some code repetition and being more semantic