Added "buy" and moved (almost) all commands to separate functions.