fixing stack overflow bug introduced at some point