Replaced deprecated APIs, other refactoring