de-nested some code for readability