buggy implementation of ajax