Fixed typecast issue with ugly code!