Updated with various bug fixes