Added comments and some parameter's sanity checking.