refactoring command to allow diagmostics. move part of commands to the library
bug fix