Implement all functions; debugging segmentation error