refactored, fixed some update problems