polishing things a bit and fixing some bugs