Applied bugfix provided by fogbrain

https://github.com/fogbrain99/KineticJS/commit/13af4a0024e32eb5789d4f79d8e6d552913c8454

https://github.com/fogbrain99/KineticJS/commit/8ad27b094c3a34872e2ae2a0b1eec421695b9366