refactored, added more trace