nearly there, somehow not working but I think I got the logical right. Needs more debugging