Reworked command sending. Made things more thread-safe.