added some bipart functions and refactor