Added Doxygen-friendly comments; Improved state control