Major refactor to simplify library interface