integer overflow fixed, problematic casting fixed.