Cleaned up a little bit, still needs some work...possibly use node.js?