vitals loop and some refactoring