add block support

Add block support and did small refactoring, like use 'instancetype' instead 'id'