fixed a LOT OF NASTY BUGS