val function and some other useful changes