Modified codes, added functions