Rearranged C++, C and Python code

Signed-off-by: Ionut Radu <ihonius@gmail.com>