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