Decent sized commit, feel free to read the code