fixing many bugs and enhancements