refactor + add exception logging