Fixed build for gcc 4.8 on debian. Fixed factory to no longer return deallocated objects.