abstracted some code into protected functions