implemented ideas from HN thread