lib: More optimisation tricks for panic and cleanups

Signed-off-by: Andrew 'Necromant' Andrianov <andrew@ncrmnt.org>