removed unnecessary typecasts and improved performance