fully implemented foldering and cleaned up a bit