a bit of code cleanup and optimization