modularized and worked on saving binary