Got some comments from Mats, he restructured the code a little