Adjusted the handling slightly and added some more checks