cleaning up older solutions, improved to O(1) complexity