Added rotate function.
Added debug information for bug fixing purpose