Fixed #507 and worked on #494