Cleaned up some bugs and added main