bugs fixed and cleanup