Added comments and more parameter checks