Improved efficiency and added magical weapon generation function