square function improved