Fix bugs in initial implementation