tweaked the function because the cast was not working