final version with all bugs fixed