Fix array removal

was using remove(index) rather than remove(object) was using int
primitive rather than Integer object.
Also fixed a bit of code repeatition.
Partial fix to the building issue

Gathering materials seems to override other commands alot. Hacky fix is
to sit in a loop reissuing the command until it actually happens. Seems
slightly more successful than waiting for POSH to call it again. Also
fixed array removal here as well.