Fixed precedence and added testcases