First commit. This code works fine and tested for a long time on live server.