Seems like the code works, now for debuging and refactoring