Fixed many bugs left over from extraction from the original project