fixed update and select. Some refactoring too