edited script into smaller modules for better future development, improved content negotiation, todo: JSON error message