simplification and bug fixes