first implementation, lacks debugging