Carrying on improving the code, thanks to the awesome people on reddit.