Add add functionality and fix bugs