finally got it working

Not perfect, a lot of my code could have been better but it works and
that is what matters