first working version - reduce some printfs