improved some functions to be shorter and more dynamic