fixing some things to make the code more dry