Updated with bug fixes