Fixes some bugs, but needs refactor on SAP