Replaced unsafe code with working