Code port finished, debugging and testing needed
[Temp] to be amended