clean up style a bit and make more robust