added error push/pop and handled some error cases