upgraded apns protocol to the newest version; added basic error checking for apns
minor refactor to make sure there're no dangling sockets and files