Tests and Final bug fixes