removes the null pointer when cancelling - also restructures a bit for readability