Working version
Fix bugs