refactor and add new functions to make things easier