Fixed decode

Fixed bug in decode
Fixed bug

Added window restriction