Removing duplicated code, and fixing memory leak in boss