Update apl and fix bugs