working version without timer