improve conditionals and remove unnecessary vars