Improved precedence calculations. Fixes #4
Set last on each press