Fix bugs and refactor for releasing to CocoaPods