updated to fix bugs. should compile