Removed using of deprecated API, split long method to smaller ones.