Added a main, completed missing functions