moved stuff around, modularized code