Added square cast function