Added selftest, better sanity checks, renamed index to PHP file