this is pretty hard to follow, please simplify or comment