first ugly solver implementation