refactored for tick event