refactor some functions to match jQuery API