optimize code & queries + fix query result bug
optimize code