Fixed #1 and some minor improvements