Rewrite and refactoring to fix results, and separate them by type