cleaned up structure, fixed bugs