cleaned up/modularized code more