Code cleanup, better stack trace