Fix windows handle, clean code