Major refactor and lib update