lots of small changes made. Added a more precise return statement