more up to date version with some cool new things I am too lazy to explain - you can check the diff