Removed unecessary active bool var
Polished code in the while loops