reorganizing and bug fixes