simplified main, added functions, working sim