bug fixes, improvement to organize