remove error messages and improve code