some code cleanup, thanks to Agamemnus