fixed a lot of stuff

made some bugfixes, tweaks and improvements.