added required messages and cleaned code