Fixed a bug. Thanks to @jhbruhn. Optimized code style a bit.