Final code, everything should work