Fixed mistakes in code. Added more logging to server. Fixed mistakes in template.