Fixed memory bug and extended code to behave in the same way as under iOS 7