cleanup, introduce some exception handling