FIX #135 #511 and added a test