Remove bugs, rewrite function and command detection