Final initial version with code fixes