Modularized many functions, hopefully more scaleable, requires commenting and still have a bug