Allocating objects in the constructor causes problems