cleaned up code, prepared ajax functions