some more code clearning and more testing, but with the code saved this time