Added modularity and new class file for reuse, removed redundant loops
and conversions.