changed unsafe code to reflect current changes in master