seems to work
a bit of code cleanup