add reset and restart functions and clean code