cleanup and slight optimization