fix negative position problem (e.g. -1 => M1);
fix ceil function bug;