added tests and fixed bugs in appjs