Better version without threads