refactored a bit + adding some ajax stuff