Cleaned up ajax implementation (a little)