minor improvements + organizing code