Added security and moved code to server