improved some code for readability