Fixed major bugs and added some functionality