Cleaned up code
First search-based approach works for smaller sizes