My master thesis code. A little rough though.