Add error control and remove dirty prints