My final pull request

Code is messed up, but I have no time to fix it. If somebody can improve it, please go ahead!