bug fixes in algorithm, and cleared fortran warnings