improve output message and clean the code