moved some calcs outside of main loop; added warnings