rewriting of a very stupid way to do things