Fixed memory leaks + updated for Mavericks