progress towards better modularization, contains bugs