Fixed bug #3, further improvements