Add more comments and fix warnings